{include file="common/header"/}
<style>
#AdminForm i.layui-icon{ font-weight: bold; }
#AdminForm i.layui-icon-ok{ color: green }
#AdminForm i.layui-icon-close{ color: red }
</style>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-body">
                <div class="layui-row">
                  <div class="layui-btn-group">
                      <a href="javascript:;" class="layui-btn layui-btn-sm" onclick="open_frame('{:lang('add')}字段','{:url('fieldadd')}?moduleid={:input('id')}');"><i class="layui-icon layui-icon-add-circle"></i>{:lang('add')}字段</a>
                  </div>
                </div>
                <div class="layui-row">
                  <form  lay-filter="form" class="layui-form">
                  <div class="item_list">
                    <table class="layui-table list" lay-filter="list" style="min-width: 800px; user-select: auto;">
                      <colgroup>
                        <col width="150"></colgroup>
                      <thead>
                        <tr>
                          <th>字段名</th>
                          <th>别名</th>
                          <th>字段类型</th>
                          <th>必填</th>
                          <th>排序</th>
                          <th class="item_action">操作</th>
                        </tr>
                      </thead>
                      <tbody>
                        {volist name='list' id='list'}
                        <tr>
                          <td>{$list.field}</td>
                          <td>{$list.name}</td>
                          <td>{$list.type}</td>
                          <td>{eq name="list.required" value="1"}<i class="layui-icon layui-icon-ok"></i>{else}<i class="layui-icon layui-icon-close"></i>{/eq}</td>
                          <td>
                            <input name="{$list.id}" data-id="{$list.id}" class="list_order layui-input" value="{$list.sort}" size="10"/>
                          </td>
                          <td class="item_action">
                            <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-sm" href="javascript:;" onclick="open_frame('编辑','{:url('fieldEdit')}?moduleid={$list.moduleid}&id={$list.id}')"><i class="layui-icon"></i>{:lang('edit')}</a>
                            <a data-href="{:url('fieldDel')}?moduleid={$list.moduleid}&id={$list.id}" class="layui-btn layui-btn-sm layui-btn-danger" id="delField" >{:lang('del')}</a>
                            </div>
                          </td>
                        </tr>
                        {/volist}
                        {empty name="list"}
                        <tr> 
                        <td colspan="12" align="center">暂时没有数据</td>
                        </tr>
                        {/empty}
                      </tbody>
                    </table>
                  </div>
                </form>
                </div>
              </div>
                
            </div>
        </div>
    </div>
</div>
<script>
$(function(){
    $(document).on('click','#stateyes',function(){
        var fieldid = $(this).attr('data-id');
        loading = layer.load(1, {shade: [0.1, '#fff']});
        $.post('{:url("fieldStatus")}', {id: fieldid}, function (res) {
            window.location.href = "{:url('field')}?id={:input('id')}"
        });
    })
    $(document).on('click','#delField',function(){
        var url = $(this).attr('data-href');
        layer.confirm('确定要删除吗', function(index){
              loading =layer.load(1, {shade: [0.1,'#fff']});
              $.post(url,function(res){
                  layer.close(loading);
                  if(res.code>0){
                      layer.msg(res.msg);
                      window.location.reload();
                  }else{
                      layer.msg(res.msg);
                  }
              });
          });
    })
    
})
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;
        $('body').on('blur','.list_order',function() {
            var id = $(this).attr('data-id');
            var sort = $(this).val();
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post('{:url("listOrder")}',{id:id,sort:sort,moduleid:"{:input('id')}"},function(res){
                layer.close(loading);
                if(res.code==1){
                    layer.msg(res.msg,{time:1000,icon:1});
                    window.location.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            })
        })
    });
</script>